package com.dk.controller;


import com.dk.data.Result;
import com.dk.em.ConstantEnum;
import com.dk.pojo.TContentOrder;
import com.dk.service.ITContentOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 广告订单表 前端控制器
 * </p>
 *
 * @author author
 * @since 2021-10-29
 */
@RestController
@RequestMapping("/t-content-order")
@Api(value = "广告订单接口")
public class TContentOrderController {

    @Autowired
    private ITContentOrderService orderService;

    //根据ID查询
    @GetMapping("/{id}")
    @ApiOperation(value = "广告订单查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "广告订单id",required = true,paramType = "path")
    })
    public Result findById(@PathVariable("id") Long id){ //@RequestBody  接收前台以json格式传进来的参数

        TContentOrder order = orderService.getById(id);

        return Result.bulid(ConstantEnum.SUCCESS).setResult(order);
    }

    //增加
    @PostMapping("/{contentId}/{adminId}/{price}")
    @ApiOperation(value = "广告订单增加接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "contentId",value = "广告id",required = true,paramType = "path"),
            @ApiImplicitParam(name = "adminId",value = "用户id",required = true,paramType = "path"),
            @ApiImplicitParam(name = "price",value = "广告订单价格",required = true,paramType = "path")
    })
    public Result add(@PathVariable("contentId") Integer contentId,@PathVariable("adminId") Integer adminId,
                      @PathVariable("price") BigDecimal price){
        TContentOrder order = new TContentOrder();
        order.setContentId(contentId);
        order.setAdminId(adminId);
        order.setPrice(price);
        orderService.save(order);
        return Result.bulid(ConstantEnum.SUCCESS);
    }


    //修改
    @PutMapping("/{id}/{contentId}/{adminId}/{price}/{status}")
    @ApiOperation(value = "广告订单修改接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "广告订单id",required = true,paramType = "path"),
            @ApiImplicitParam(name = "contentId",value = "广告图片地址",required = true,paramType = "path"),
            @ApiImplicitParam(name = "adminId",value = "用户id",required = true,paramType = "path"),
            @ApiImplicitParam(name = "price",value = "广告订单价格",required = true,paramType = "path"),
            @ApiImplicitParam(name = "status",value = "广告订单状态",required = true,paramType = "path")
    })
    public Result update(@PathVariable("id") Long id,@PathVariable("contentId") Integer contentId,@PathVariable("adminId") Integer adminId,
                         @PathVariable("price") BigDecimal price,@PathVariable("status") Integer status){

        TContentOrder order = new TContentOrder();
        order.setId(id);
        order.setContentId(contentId);
        order.setAdminId(adminId);
        order.setPrice(price);
        order.setStatus(status);
        orderService.updateById(order);
        return Result.bulid(ConstantEnum.SUCCESS);
    }

    //删除
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "广告订单批量删除接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids",value = "广告订单id",required = true,paramType = "path")
    })
    public Result delete(@PathVariable("ids") Long[] ids){
        orderService.removeByIds(Arrays.asList(ids));
        return Result.bulid(ConstantEnum.SUCCESS);
    }

    //全部查询
    @RequestMapping(value = "findAll",method = RequestMethod.GET)
    @ApiOperation(value = "广告订单全部查询接口")
    public Result findAll(){
        List<TContentOrder> list = orderService.list();
        return Result.bulid(ConstantEnum.SUCCESS).setResult(list);
    }


}
